import request from '@/router/axios';



export const getCount =()=>{
  return request({
    url: '/api/blade-desk/notice/count',
    method: 'get',
  })

}

export const getList = (current, size, params) => {
  return request({
    url: '/api/blade-desk/notice/list',
    method: 'get',
    params: {
      ...params,
      current,
      size,
    }
  })
}

export const remove = (ids) => {
  return request({
    url: '/api/blade-desk/notice/remove',
    method: 'post',
    params: {
      ids,
    }
  })
}

export const add = (row) => {
  var c=row.content ;
  row.content=htmlencode(c)
  return request({
    url: '/api/blade-desk/notice/submit',
    method: 'post',
    data: row,
    params:{
    }
  })
}

export const update = (row) => {
  var c=row.content ;
  row.content=htmlencode(c)
  return request({
    url: '/api/blade-desk/notice/submit',
    method: 'post',
    data: row,
    params:{
  }
  })
}

export const getNotice = (id) => {
  return request({
    url: '/api/blade-desk/notice/detail',
    method: 'get',
    params: {
      id
    }
  })
}

function htmlencode(html) {
  var temp = document.createElement ("div");
  //2.然后将要转换的字符串设置为这个元素的innerText(ie支持)或者textContent(火狐，google支持)
  (temp.textContent != undefined ) ? (temp.textContent = html) : (temp.innerText = html);
  //3.最后返回这个元素的innerHTML，即得到经过HTML编码转换的字符串了
  var output = temp.innerHTML;
  temp = null;
  return output;
}

export const htmldecode=(html)=> {
//1.首先动态创建一个容器标签元素，如DIV
  var temp = document.createElement("div");
  //2.然后将要转换的字符串设置为这个元素的innerHTML(ie，火狐，google都支持)
  temp.innerHTML = html;
  //3.最后返回这个元素的innerText(ie支持)或者textContent(火狐，google支持)，即得到经过HTML解码的字符串了。
  var output = temp.innerText || temp.textContent;
  temp = null;
  return output;

}


